/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {AppRegistry, Text, View} from 'react-native';
import PlayList from './src/bundles/PlayList/PlayListPage';
import MusicPlay from './src/bundles/MusicPlay/MusicPlayPage';
import React from 'react';

// 使用setWrapperComponentProvider来包装根组件。
// children: 渲染RN侧组件；<Text> 原生侧传递过来的数据内容。
AppRegistry.setWrapperComponentProvider(appParams => {
  return function ({children, ...otherProps}) {
    if (
      Object.keys(otherProps.initialProps).includes('styles') &&
      Object.keys(otherProps.initialProps).includes('stringParam')
    ) {
      return (
        <View style={otherProps.initialProps.styles.container}>
          <View
            style={{
              borderRadius: 10,
              backgroundColor: '#FAE6B1',
              height: 100,
              justifyContent: 'center',
              alignItems: 'center',
            }}>
            <Text style={otherProps.initialProps.styles.apiFontSize}>
              {otherProps.initialProps.stringParam}
            </Text>
          </View>
          <View>{children}</View>
        </View>
      );
    } else {
      return children;
    }
  };
});

AppRegistry.registerComponent('PlayList', () => PlayList);
AppRegistry.registerComponent('MusicPlay', () => MusicPlay);
